﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using PB.Airsoft.Core;
using PB.Airsoft.Business.Account;
using PB.Airsoft.Provider.NHibernate.Account;
using PB.Airsoft.NHibernateWrapper;
using PB.Airsoft.Business.Account.Interfaces;
using PB.Airsoft.Business.Utilities.Caching;
using PB.Airsoft.Web.Business.Utilities.Caching;
using PB.Airsoft.Core.Unity;
using PB.Airsoft.Business.Account.Entities;
using PB.Airsoft.Business.User;
using PB.Airsoft.Provider.NHibernate.User;
using PB.Airsoft.Business.User.Interfaces;
using PB.Airsoft.Business.Shop.Interfaces;
using PB.Airsoft.Business.Shop.Entities;
using PB.Airsoft.Business.Shop;
using PB.Airsoft.Provider.NHibernate.Shop;
using PB.Airsoft.Business.Item;
using PB.Airsoft.Provider.NHibernate.Item;
using PB.Airsoft.Web.Business.Interfaces;
using PB.Airsoft.Web.Business;
using PB.Airsoft.Business.User.Entities;
using PB.Airsoft.Business.Item.Interfaces;
using PB.Airsoft.Business.Item.Entities;

namespace PB.Airsoft.Web
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            InitializeUnity();
        }

        private void InitializeUnity()
        {
            IoC.Initialize();

            IoC.RegisterSingletonType<IAppContext, AppContext>();

            IoC.RegisterInstance<ISessionCreator>(new SessionCreator());
            IoC.RegisterSingletonType<CacheManager, WebCacheManager>();

            RegisterEntities();

            RegisterProviders();
        }

        private void RegisterEntities()
        {
            IoC.RegisterType<IUserAccount, UserAccount>();
            IoC.RegisterType<IUser, PB.Airsoft.Business.User.Entities.User>();
            IoC.RegisterType<IShopLot, ShopLot>();
            IoC.RegisterType<IItem, Item>();
            IoC.RegisterType<IUserInventoryItem, UserInventoryItem>();
        }

        private void RegisterProviders()
        {
            IoC.RegisterType<AccountProvider, NHibernateAccountProvider>().SetDefaultConstructor();
            IoC.RegisterType<UserProvider, NHibernateUserProvider>().SetDefaultConstructor();
            IoC.RegisterType<ShopProvider, NHibernateShopProvider>().SetDefaultConstructor();
            IoC.RegisterType<ItemProvider, NHibernateItemProvider>().SetDefaultConstructor();
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}